<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
<th:block th:include="include :: header('新增党员基本信息')" />
<th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-member-add">
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">党员编号：</label>
				<div class="col-sm-8">
					<input name="memberId" id="memberId" class="form-control" type="text" maxlength="10" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">党员姓名：</label>
				<div class="col-sm-8">
					<input name="memberName" class="form-control" type="text" maxlength="30" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">身份证号：</label>
				<div class="col-sm-8">
					<input name="card" class="form-control" type="text" maxlength="18" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">出生年月日：</label>
				<div class="col-sm-8">
					<!-- <input name="birthday" class="form-control" type="text" required> -->
					 <input type="text" maxlength="10" class="form-control time-input" name="birthday"  required placeholder="请填写出生年月日">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">政治生日：</label>
				<div class="col-sm-8">
					<!-- <input name="partyBirthday" class="form-control" type="text"
						required> -->
					<input type="text" maxlength="10" name="partyBirthday" class="form-control time-input" required placeholder="请填写政治生日">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">行政级别：</label>
				<div class="col-sm-8">
					<select name="adminLevel" class="form-control m-b"
						th:with="type=${@dict.getType('admin_level')}" required>
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}"
							th:value="${dict.dictValue}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">党内职务：</label>
				<div class="col-sm-8">
					<select name="partyDuty" class="form-control m-b"
						th:with="type=${@dict.getType('party_duty')}" required>
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}"
							th:value="${dict.dictValue}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">所属支部：</label>
				<div class="col-xs-4">
					<select id="orgZb" class="form-control select2-multiple" name="orgId">
						<option th:each="orgZb:${orgZbs}" th:value="${orgZb.orgId}"
							th:text="${orgZb.orgName}"></option>
					</select>
				</div>
				<!-- <div class="col-sm-8">
                    <input name="orgId" class="form-control" type="text" required>
                </div> -->
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">所属党小组：</label>
				<div class="col-xs-4">
					<select id="orgDxz" class="form-control select2-multiple" name="orgGid">
						<option value="">请选择</option>
						<option th:each="orgDxz:${orgDxzs}" th:value="${orgDxz.orgId}"
							th:text="${orgDxz.orgName}"></option>
					</select>
				</div>
				<!-- <div class="col-sm-8">
					<input name="orgGid" class="form-control" type="text">
				</div> -->
			</div>
			<div class="form-group">
                 <label class="col-sm-4 control-label is-required">登录密码：</label>
                 <div class="col-sm-8">
                     <div class="input-group">
                         <input id="password" name="memberPwd" placeholder="请输入登录密码" class="form-control" type="password" th:value="${@config.getKey('sys.user.initPassword')}" required>
                         <span class="input-group-addon" title="登录密码,鼠标按下显示密码"
                             onmousedown="$('#password').attr('type','text')"
                             onmouseup="$('#password').attr('type','password')"><i class="fa fa-key"></i></span>
                     </div>
                 </div>
             </div>
			<div class="form-group">
				<label class="col-xs-2 control-label">角色：</label>
				<div class="col-xs-10">
					<label th:each="role:${roles}" class="check-box"> <input
						name="role" type="checkbox" th:value="${role.roleId}"
						th:text="${role.roleName}" th:disabled="${role.status == '1'}">
					</label>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: select2-js" />
    <th:block th:include="include :: bootstrap-select-js" />
	<script th:inline="javascript">
		var prefix = ctx + "business/member"
		var userprefix = ctx + "system/user";
		$("#form-member-add").validate({
			focusCleanup : true,
			rules:{
                card:{
                    isIdCardNo:true,
                },
                memberId:{
        			minlength: 2,
        			maxlength: 20,
        			remote: {
                        url: userprefix + "/checkLoginNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                        	"loginName": function() {
                                return $.common.trim($("#memberId").val());
                            }
                        },
                        dataFilter: function(data, type) {
                        	return $.validate.unique(data);
                        }
                    }
        		},
        		memberPwd:{
        			minlength: 5,
        			maxlength: 20
        		}
            },
            messages: {
                "memberId": {
                    remote: "用户已经存在"
                }
            }
		});

		function submitHandler() {
			if ($.validate.form()) {
				// 获取党支部数据和党小组数据
				var data = $("#form-member-add").serializeArray();
	        	var roleIds = $.form.selectCheckeds("role");
	        	if(roleIds.length==0){
	        		$.modal.alertWarning("请至少选择一个角色");
	        		return;
	        	}
	        	data.push({"name": "roleIds", "value": roleIds});
				$.operate.save(prefix + "/add", data);
			}
		}
		
		$(function() {
			
            $('#orgZb').select2({
                placeholder: "请选择党支部",
                allowClear: true
            });
            $('#orgDxz').select2({
                placeholder: "请选择党小组",
                allowClear: true
            });
            
            jQuery.validator.addMethod("isIdCardNo", function (value, element){
		        return this.optional(element) || isIdCardNo(value);
		    },"请正确输入您的身份证号码");
			
            function isIdCardNo(num) {
                var factorArr = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5,8, 4, 2, 1];
                var parityBit = ["1", "0", "X", "9", "8", "7", "6", "5", "4","3", "2"];
                var varArray= [];
                var lngProduct = 0;
                var intCheckDigit;
                var intStrLen = num.length;
                var idNumber= num;
                //initialize
                if(intStrLen !== 18) {
                    return false;
                }
                // check andset value
                for (i = 0;i < intStrLen; i++) {
                    varArray[i] = idNumber.charAt(i);
                    if ((varArray[i] < '0' || varArray[i]> '9') && (i !== 17)){
                        return false;
                    } else if (i < 17) {
                        varArray[i] = varArray[i] * factorArr[i];
                    }
                }

                if(intStrLen === 18) {
                    //check date
                    var date8 = idNumber.substring(6, 14);
                    if (!isDate8(date8)) {
                        return false;
                    }
                    // calculate the sum of the products
                    for (i = 0; i < 17; i++) {
                        lngProduct = lngProduct + varArray[i];
                    }
                    // calculate the check digit
                    intCheckDigit = parityBit[lngProduct % 11];
                    // check last digit
                    if (varArray[17] != intCheckDigit) {
                        return false;
                    }
                }else{
                    return false;
                }
                return true;
            }

            
            
            function isDate8(sDate) {
                if(!/^[0-9]{8}$/.test(sDate)) {
                    return false;
                }
                var year,month, day;
                year =sDate.substring(0, 4);
                month =sDate.substring(4, 6);
                day =sDate.substring(6, 8);
                var iaMonthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,31];
                if (year< 1700 || year > 2500) {
                    return false;
                }
                if (((year %4 == 0) && (year % 100 != 0)) ||(year % 400 == 0)) {
                    iaMonthDays[1] = 29;
                }
                if (month< 1 || month > 12) {
                    return false;
                }
                return !(day < 1 || day > iaMonthDays[month - 1]);
            }

            
            
        })
        
        
       
	</script>
</body>
</html>